package app.common.utils.cjt.vo;

import app.common.utils.cjt.ao.SaleDeliveryCreateAo;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 销售出库单查询响应
 * @author feizns
 * @since 2023/04/06
 */
@NoArgsConstructor
@Data
public class WmsStockoutSalesQueryWithDetailVo {

    /**
     * total_count
     */
    private Integer total_count;
    /**
     * order
     */
    private List<Order> order;

    /**
     * Order
     */
    @NoArgsConstructor
    @Data
    public static class Order {
        /**
         * logistics_name
         */
        private String logistics_name;
        /**
         * details_list
         */
        private List<DetailsList> details_list;
        /**
         * consign_time
         */
        private String consign_time;
        /**
         * post_amount
         */
        private Integer post_amount;
        /**
         * fenxiao_nick
         */
        private String fenxiao_nick;
        /**
         * trade_time
         */
        private Long trade_time;
        /**
         * receiver_dtb
         */
        private String receiver_dtb;
        /**
         * bad_reason
         */
        private Integer bad_reason;
        /**
         * print_remark
         */
        private String print_remark;
        /**
         * employee_no
         */
        private String employee_no;
        /**
         * discount
         */
        private Double discount;
        /**
         * tax_rate
         */
        private Integer tax_rate;
        /**
         * trade_id
         */
        private Integer trade_id;
        /**
         * trade_label
         */
        private String trade_label;
        /**
         * shop_remark
         */
        private String shop_remark;
        /**
         * invoice_id
         */
        private Integer invoice_id;
        /**
         * modified
         */
        private String modified;
        /**
         * receiver_country
         */
        private Integer receiver_country;
        /**
         * order_type
         */
        private Integer order_type;
        /**
         * shop_no
         */
        private String shop_no;
        /**
         * picklist_seq
         */
        private Integer picklist_seq;
        /**
         * seq_no
         */
        private Integer seq_no;
        /**
         * receiver_area
         */
        private String receiver_area;
        /**
         * customer_no
         */
        private String customer_no;
        /**
         * refund_status
         */
        private Integer refund_status;
        /**
         * receiver_province
         */
        private Integer receiver_province;
        /**
         * buyer_message
         */
        private String buyer_message;
        /**
         * created
         */
        private Long created;
        /**
         * weight
         */
        private Double weight;
        /**
         * block_reason
         */
        private Integer block_reason;
        /**
         * tax
         */
        private Integer tax;
        /**
         * logistics_code
         */
        private String logistics_code;
        /**
         * shop_name
         */
        private String shop_name;
        /**
         * shop_platform_id
         */
        private Integer shop_platform_id;
        /**
         * pay_time
         */
        private Long pay_time;
        /**
         * shop_id
         */
        private Integer shop_id;
        /**
         * warehouse_name
         */
        private String warehouse_name;
        /**
         * goods_total_cost
         */
        private Double goods_total_cost;
        /**
         * nick_name
         */
        private String nick_name;
        /**
         * trade_no
         */
        private String trade_no;
        /**
         * warehouse_mapping_code
         */
        private String warehouse_mapping_code;
        /**
         * id_card_type
         */
        private Integer id_card_type;
        /**
         * status
         */
        private Integer status;
        /**
         * package_fee
         */
        private Integer package_fee;
        /**
         * order_no
         */
        private String order_no;
        /**
         * src_trade_no
         */
        private String src_trade_no;
        /**
         * post_fee
         */
        private Integer post_fee;
        /**
         * receiver_city
         */
        private Integer receiver_city;
        /**
         * invoice_title
         */
        private String invoice_title;
        /**
         * id_card
         */
        private String id_card;
        /**
         * remark
         */
        private String remark;
        /**
         * sub_platform_id
         */
        private Integer sub_platform_id;
        /**
         * goods_count
         */
        private Integer goods_count;
        /**
         * stockout_id
         */
        private Integer stockout_id;
        /**
         * cod_amount
         */
        private Integer cod_amount;
        /**
         * flag_name
         */
        private String flag_name;
        /**
         * src_order_no
         */
        private String src_order_no;
        /**
         * logistics_id
         */
        private Integer logistics_id;
        /**
         * warehouse_no
         */
        private String warehouse_no;
        /**
         * receiver_telno
         */
        private String receiver_telno;
        /**
         * receiver_zip
         */
        private String receiver_zip;
        /**
         * invoice_content
         */
        private String invoice_content;
        /**
         * trade_status
         */
        private Integer trade_status;
        /**
         * receiver_name
         */
        private String receiver_name;
        /**
         * invoice_type
         */
        private Integer invoice_type;
        /**
         * currency
         */
        private String currency;
        /**
         * picklist_no
         */
        private String picklist_no;
        /**
         * logistics_type
         */
        private Integer logistics_type;
        /**
         * trade_from
         */
        private Integer trade_from;
        /**
         * delivery_term
         */
        private Integer delivery_term;
        /**
         * logistics_no
         */
        private String logistics_no;
        /**
         * receiver_district
         */
        private Integer receiver_district;
        /**
         * goods_total_amount
         */
        private Double goods_total_amount;
        /**
         * receivable
         */
        private Double receivable;
        /**
         * receiver_mobile
         */
        private String receiver_mobile;
        /**
         * salesman_no
         */
        private String salesman_no;
        /**
         * stock_check_time
         */
        private Long stock_check_time;
        /**
         * cs_remark
         */
        private String cs_remark;
        /**
         * platform_id
         */
        private Integer platform_id;
        /**
         * paid
         */
        private Double paid;
        /**
         * receiver_address
         */
        private String receiver_address;
        /**
         * trade_type
         */
        private Integer trade_type;
        /**
         * logistics_print_status
         */
        private Integer logistics_print_status;
        /**
         * fullname
         */
        private String fullname;
        /**
         * customer_name
         */
        private String customer_name;
        /**
         * logistics_list
         */
        private List<LogisticsList> logistics_list;
        /**
         * warehouse_id
         */
        private Integer warehouse_id;

        public SaleDeliveryCreateAo.Dto toSaleDeliveryCreateAo() {
            SaleDeliveryCreateAo.Dto dto = new SaleDeliveryCreateAo.Dto();
            dto.setBusinessType(new SaleDeliveryCreateAo.Dto.BusinessType("15"));
            dto.setExternalCode(this.getOrder_no());
            dto.setProject(new SaleDeliveryCreateAo.Dto.Project(afterTruncationBar(this.getShop_no())));
            dto.setCustomer(new SaleDeliveryCreateAo.Dto.Customer(this.getShop_no()));
            dto.setCode(this.getOrder_no());
            dto.setVoucherDate(this.getConsign_time());
            dto.setMemo(String.format("编号：[%s] 备注：[%s] 类型：[%s] 订单编号：[%s] 系统订单编号：[%s]", dto.getExternalCode(), this.getRemark(), "销售出库单", this.getTrade_no(), this.getSrc_trade_no()));
            dto.setWarehouse(new SaleDeliveryCreateAo.Dto.Warehouse(this.getWarehouse_no()));
            List<SaleDeliveryCreateAo.Dto.SaleDeliveryDetails> list = this.details_list.stream()
                    .map(DetailsList::toSaleDeliveryDetails)
                    .collect(Collectors.toList());
            dto.setSaleDeliveryDetails(list);
            return dto;
        }

        /**
         * 将原字符中的'-'截断：例："023-1" -> "023"
         * @param shopNo 商店没有
         * @return {@link String}
         */
        public String afterTruncationBar(String shopNo) {
            if ( shopNo != null ) {
                int index = shopNo.indexOf("-");
                if ( index != -1 )
                    return shopNo.substring(0, index);
            }
            return shopNo;
        }

        /**
         * DetailsList
         */
        @NoArgsConstructor
        @Data
        public static class DetailsList {
            /**
             * rec_id
             */
            private Integer rec_id;
            /**
             * stockout_id
             */
            private Integer stockout_id;
            /**
             * spec_id
             */
            private Integer spec_id;
            /**
             * goods_count
             */
            private Integer goods_count;
            /**
             * goods_amount
             */
            private Double goods_amount;
            /**
             * paid
             */
            private Double paid;
            /**
             * brand_no
             */
            private String brand_no;
            /**
             * brand_name
             */
            private String brand_name;
            /**
             * remark
             */
            private String remark;
            /**
             * goods_name
             */
            private String goods_name;
            /**
             * goods_no
             */
            private String goods_no;
            /**
             * spec_name
             */
            private String spec_name;
            /**
             * spec_code
             */
            private String spec_code;
            /**
             * spec_no
             */
            private String spec_no;
            /**
             * cost_price
             */
            private Double cost_price;
            /**
             * weight
             */
            private Double weight;
            /**
             * total_amount
             */
            private Double total_amount;
            /**
             * goods_id
             */
            private Integer goods_id;
            /**
             * prop1
             */
            private String prop1;
            /**
             * prop2
             */
            private String prop2;
            /**
             * prop3
             */
            private String prop3;
            /**
             * prop4
             */
            private String prop4;
            /**
             * prop5
             */
            private String prop5;
            /**
             * prop6
             */
            private String prop6;
            /**
             * platform_id
             */
            private Integer platform_id;
            /**
             * refund_status
             */
            private Integer refund_status;
            /**
             * tax_rate
             */
            private BigDecimal tax_rate;
            /**
             * barcode
             */
            private String barcode;
            /**
             * sale_order_id
             */
            private Integer sale_order_id;
            /**
             * gift_type
             */
            private Integer gift_type;
            /**
             * src_oid
             */
            private String src_oid;
            /**
             * src_tid
             */
            private String src_tid;
            /**
             * from_mask
             */
            private Integer from_mask;

            /**
             * 单位名字
             */
            private String unit_name;
            /**
             * goods_type
             */
            private Integer goods_type;
            /**
             * good_prop1
             */
            private String good_prop1;
            /**
             * good_prop2
             */
            private String good_prop2;
            /**
             * good_prop3
             */
            private String good_prop3;
            /**
             * good_prop4
             */
            private String good_prop4;
            /**
             * good_prop5
             */
            private String good_prop5;
            /**
             * good_prop6
             */
            private String good_prop6;
            /**
             * suite_no
             */
            private String suite_no;
            /**
             * src_order_detail_id
             */
            private Integer src_order_detail_id;
            /**
             * share_post_amount
             */
            private Double share_post_amount;
            /**
             * is_package
             */
            private Boolean is_package;
            /**
             * sell_price
             */
            private Double sell_price;
            /**
             * market_price
             */
            private BigDecimal market_price;
            /**
             * share_price
             */
            private Double share_price;
            /**
             * discount
             */
            private Double discount;
            /**
             * share_amount
             */
            private BigDecimal share_amount;
            /**
             * position_details_list
             */
            private List<PositionDetailsList> position_details_list;

            public SaleDeliveryCreateAo.Dto.SaleDeliveryDetails toSaleDeliveryDetails() {
                SaleDeliveryCreateAo.Dto.SaleDeliveryDetails details = new SaleDeliveryCreateAo.Dto.SaleDeliveryDetails();
                details.setInventory(new SaleDeliveryCreateAo.Dto.SaleDeliveryDetails.Inventory(this.getSpec_no()));
                details.setQuantity(this.getGoods_count());
                details.setOrigDiscountPrice(this.getMarket_price());
                details.setTaxRate(this.getTax_rate());
                details.setOrigDiscountAmount(this.getShare_amount());
                details.setOrigTaxPrice(details.getOrigDiscountPrice());
                details.setOrigTaxAmount(details.getOrigDiscountAmount());
                details.setUnit(new SaleDeliveryCreateAo.Dto.SaleDeliveryDetails.Unit(this.getUnit_name()));
                return details;
            }

            /**
             * PositionDetailsList
             */
            @NoArgsConstructor
            @Data
            public static class PositionDetailsList {
                /**
                 * rec_id
                 */
                private Integer rec_id;
                /**
                 * stockout_detail_id
                 */
                private Integer stockout_detail_id;
                /**
                 * position_id
                 */
                private Integer position_id;
                /**
                 * position_no
                 */
                private String position_no;
                /**
                 * batch_no
                 */
                private String batch_no;
                /**
                 * expire_date
                 */
                private String expire_date;
                /**
                 * position_goods_count
                 */
                private Integer position_goods_count;
            }
        }

        /**
         * LogisticsList
         */
        @NoArgsConstructor
        @Data
        public static class LogisticsList {
            /**
             * rec_id
             */
            private Integer rec_id;
            /**
             * stockout_id
             */
            private Integer stockout_id;
            /**
             * logistics_id
             */
            private Integer logistics_id;
            /**
             * logistics_no
             */
            private String logistics_no;
            /**
             * calc_weight
             */
            private Double calc_weight;
            /**
             * weight
             */
            private Double weight;
            /**
             * postage
             */
            private Integer postage;
            /**
             * remark
             */
            private String remark;
            /**
             * length
             */
            private Integer length;
            /**
             * width
             */
            private Integer width;
            /**
             * height
             */
            private Integer height;
            /**
             * package_name
             */
            private String package_name;
            /**
             * logistics_name
             */
            private String logistics_name;
            /**
             * volume
             */
            private String volume;
        }
    }
}
